package com.disruptor.demo.handler;

import com.disruptor.demo.model.SeriesDataEvent;
import com.disruptor.demo.model.dto.Data;
import com.lmax.disruptor.WorkHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author <a href="mailto:18335553083@163.com">Mr_He</a>
 * @Copyright (c)</   b> HeC<br/>
 * @createTime 2018/8/2 8:27
 * @Description: 消费者1
 */
public class SeriesDataEventHandler implements WorkHandler<SeriesDataEvent> {

    private Logger logger = LoggerFactory.getLogger(SeriesDataEventHandler.class);


    @Override
    public void onEvent(SeriesDataEvent event) {
        long timeMillis = System.currentTimeMillis();
        if (null == Data.thread) {
            Data.thread = timeMillis;
            logger.info("【2】秒级并发：{}", Data.num);
            Data.num = 1L;
        } else {
            if ((timeMillis - 1000) >= Data.thread) {
                Data.thread = null;
            } else {
                Data.num++;
            }
        }
    }

}